package com.city.repository.pub;

import com.city.domain.pub.PubFilepath;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @deprecation: 公共文件索引
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-18 13:14
 */
@Repository
public interface PubFilepathRepository extends JpaRepository<PubFilepath,Integer> {

    @Query(value = "SELECT * from pub_filepath where table_name=?1 and id_index=?2", nativeQuery = true)
    List<PubFilepath> getFileIdIndex(String tableName, String idIndex);


    @Query(value = "SELECT * from pub_filepath where id_index=?1", nativeQuery = true)
    PubFilepath findByIdIndex(String time);

    @Query(value = "SELECT * from pub_filepath where id_index=?1 and table_name <> '任务表'", nativeQuery = true)
    List<PubFilepath> findListByTaskId(String taskId);

    @Query(value = "SELECT * from pub_filepath where id_index=?1 and table_name = '任务表'",nativeQuery = true)
    List<PubFilepath> findByTaskIdAndRenwu(String taskId);

    @Transactional
    @Modifying
    @Query(value = "DELETE from pub_filepath where id_index=?1 and table_name = '任务表'",nativeQuery = true)
    void deleteByTaskId(String taskId);

    @Query(value = "SELECT * from pub_filepath where type_id = ?1",nativeQuery = true)
    List<PubFilepath> findByType(Integer type);

}
